﻿using MediatR;

namespace Ordering.Domain.SeedWork
{
    public abstract class Entity
    {
        public abstract string Id { get; }

        public override bool Equals(object? obj)
        {
            if (obj == null) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != GetType()) return false;
            var other = obj as Entity;
            if (other == null) return false;
            if (other.Id != this.Id) return false;
            return true;
        }

        public override int GetHashCode()
        {
            return HashCode.Combine(Id);
        }

        private readonly List<INotification> _domainEvents = new List<INotification>();
        
        public IReadOnlyCollection<INotification> DomainEvents => _domainEvents;

        public void AddDomainEvent(INotification domainEvent)
        {
            _domainEvents.Add(domainEvent);
        }

        public void ClearDomainEvent()
        {
            _domainEvents.Clear();
        }
    }
}
